Enable compiler-managed CUDA graphs for UMA inference - #2161
Draft
mlazos wants to merge 1 commit into
Draft
Conversation
Torch compile can capture UMA compute regions, but internal neighbor generation changes the exact edge shape from one frame to the next. Those shape changes prevent reliable CUDA graph reuse even when the atom count is fixed. Expose reduce-overhead as an inference compile mode and mark prediction boundaries for CUDA graph trees. For internal NVIDIA v3 graphs, generate the neighbor list before model execution and pad its edges to a configurable bucket. Padded edges are moved beyond the cutoff so they contribute zero energy, force, and stress while keeping the compiled input shape stable. Neighbor construction remains outside capture because the released NVIDIA implementation allocates temporary buffers. The internal path is limited to CUDA, graph version 3, and non-distributed inference. External graphs can use reduce-overhead without padding. Test Plan: ``` PYTHONPATH="$PWD/src" pytest -q -s tests/core/graph/test_padded_nvidia_graph.py tests/core/models/uma/test_padded_edges.py tests/core/units/mlip_unit/test_inference_settings.py PYTHONPATH="$PWD/src" pytest -q -s tests/core/units/mlip_unit/test_predict.py::test_reduce_overhead_internal_graph_predict pre-commit run --files docs/core/common_tasks/ase_calculator.md src/fairchem/core/graph/padded_nvidia_graph.py src/fairchem/core/models/uma/escn_md.py src/fairchem/core/units/mlip_unit/api/inference.py src/fairchem/core/units/mlip_unit/predict.py tests/core/graph/test_padded_nvidia_graph.py tests/core/models/uma/test_padded_edges.py tests/core/units/mlip_unit/test_inference_settings.py tests/core/units/mlip_unit/test_predict.py ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds an opt-in
compile_mode="reduce-overhead"inference setting sotorch.compilecan use its built-in CUDA graph support for UMA.Internal NVIDIA v3 neighbor generation remains outside the captured model
regions. Before the model runs, its variable-length edge list is padded to a
configurable bucket. Padded edges are moved beyond the cutoff, so they
contribute zero energy, force, and stress while keeping the compiled tensor
shape stable across nearby molecular-dynamics frames.
This uses released
nvalchemiops 0.4.0; it does not require a patched NVIDIAlibrary or a custom outer CUDA graph runner. It depends on #2154 for the UMA
fast-GPU kernel baseline.
Performance
Measured on one H100 with:
activation_checkpointing=Falsemerge_mole=Truecompile=True,dynamic=Trueexternal_graph_gen=Falseinternal_graph_gen_version=3execution_mode="umas_fast_gpu"Both predictors were compiled and warmed in the same process. Ten alternating
20-step blocks used identical position sequences.
reduce-overheadThis is a 7.09% median QPS improvement and a 5.53% mean QPS improvement. There
were no timed recompiles. Inductor reported 29 recorded CUDA graph regions.
The measured frame had 78,424 real edges and was padded to 78,848, adding 424
masked edges (0.54%). Separate-process steady reserved memory was 9.285 GiB for
the baseline and 7.533-7.660 GiB with
reduce-overhead.Numerical checks
At the same displaced 1,000-atom frame, maximum absolute differences versus
the dynamic compile baseline were:
NVIDIA v3 returns the same edge multiset in nondeterministic order. A
same-order padded-versus-unpadded check stayed within the variation seen when
repeating the unpadded path. Direct eager checks on single- and two-system
batches were also within 5.96e-8 for energy, 8.38e-9 for forces, and 1.64e-11
for stress.
The added CUDA regression uses the real UMA-S-1p2 checkpoint. It compares
eager and
reduce-overheadenergy, forces, and stress across repeated calls,retains an earlier output to detect replay-buffer overwrites, and crosses to a
different edge bucket before returning to the original bucket.
Limitations
reduce-overheadcurrently requires CUDA and NVIDIA graph version3.
implementation allocates temporary buffers.
to a previous bucket reuses its existing compiled graph.
Test plan